home *** CD-ROM | disk | FTP | other *** search
- package test.ui;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.SystemColor;
-
- class TestStatus extends Canvas {
- public boolean fError = false;
- public int fTotal;
- public int fProgress;
- public int fProgressX;
-
- public TestStatus() {
- ((Component)this).setSize(20, 30);
- }
-
- private Color getStatusColor() {
- return this.fError ? Color.red : Color.green;
- }
-
- public void paint(Graphics g) {
- this.paintBackground(g);
- this.paintStatus(g);
- }
-
- public void paintBackground(Graphics g) {
- g.setColor(SystemColor.control);
- g.fillRect(0, 0, ((Component)this).getBounds().width, ((Component)this).getBounds().height);
- g.setColor(Color.darkGray);
- g.drawLine(0, 0, ((Component)this).getBounds().width - 1, 0);
- g.drawLine(0, 0, 0, ((Component)this).getBounds().height - 1);
- g.setColor(Color.white);
- g.drawLine(((Component)this).getBounds().width - 1, 0, ((Component)this).getBounds().width - 1, ((Component)this).getBounds().height - 1);
- g.drawLine(0, ((Component)this).getBounds().height - 1, ((Component)this).getBounds().width - 1, ((Component)this).getBounds().height - 1);
- }
-
- public void paintStatus(Graphics g) {
- g.setColor(this.getStatusColor());
- Rectangle r = new Rectangle(0, 0, this.fProgressX, ((Component)this).getBounds().height);
- g.fillRect(1, 1, r.width - 1, r.height - 2);
- }
-
- private void paintStep(int startX, int endX) {
- Graphics g = ((Component)this).getGraphics();
- g.setColor(this.getStatusColor());
- g.fillRect(startX, 1, endX - startX, ((Component)this).getBounds().height - 2);
- }
-
- public void reset() {
- this.fProgressX = 1;
- this.fProgress = 0;
- this.fError = false;
- this.paint(((Component)this).getGraphics());
- }
-
- public int scale(int value) {
- return this.fTotal > 0 ? Math.max(1, value * (((Component)this).getBounds().width - 1) / this.fTotal) : value;
- }
-
- public void setBounds(int x, int y, int w, int h) {
- super.setBounds(x, y, w, h);
- this.fProgressX = this.scale(this.fProgress);
- }
-
- public void start(int total) {
- this.fTotal = total;
- this.reset();
- }
-
- public void step(boolean successful) {
- ++this.fProgress;
- int x = this.fProgressX;
- this.fProgressX = this.scale(this.fProgress);
- if (!this.fError && !successful) {
- this.fError = true;
- x = 1;
- }
-
- this.paintStep(x, this.fProgressX);
- }
- }
-